import json
from pyecharts.charts import Map
from pyecharts.options import *
f = open("//基础/数据可视化/地图数据/疫情.txt", "r", encoding="UTF-8")
data = f.read()
f.close()
data_dict = json.loads(data)
province_data_list = data_dict["areaTree"][0]["children"]
data_list = []
for province_data in province_data_list:
    province_name = province_data["name"]
    province_confirm = province_data["total"]["confirm"]
    data_list.append((province_name,province_confirm))
# print(data_list)
map = Map()
map.add("各省确诊人数",data_list,"china")
map.set_global_opts(
    title_opts=TitleOpts(title="全国确诊人数地图"),
    visualmap_opts=VisualMapOpts(
        is_show=True,
        is_piecewise=True,
        pieces=[
            {"min": 1, "max": 9, "label": "1-9人", "color": "#CCFFFF"},
            {"min": 10, "max": 99, "label": "10-99人", "color": "#FFFF99"},
            {"min": 100, "max": 499, "label": "100-499人", "color": "#FF9966"},
            {"min": 499, "max": 999, "label": "499-999人", "color": "#FF6666"},
            {"min": 1000, "max": 9999, "label": "1000-9999人", "color": "#CC3333"},
            {"min": 10000, "label": "10000以上", "color": "#990033"}
        ]
    )
)
# 生成地图
map.render("全国确诊人数地图.html")         # 控制生成的HTML文件的名称